﻿package com.tudou.skin.common.button
{
    import com.tudou.skin.common.events.*;
    import flash.display.*;

    public class RadioButton extends Sprite implements IRadio
    {
        protected var keyArr:Array;
        protected var selectArr:Array;
        protected var index:int = -1;
        protected var buttonArr:Array;

        public function RadioButton()
        {
            selectArr = [];
            buttonArr = [];
            keyArr = [];
            return;
        }// end function

        public function get activeKey() : String
        {
            return keyArr[index];
        }// end function

        public function getSkin() : InteractiveObject
        {
            return this;
        }// end function

        public function setEnable(param1:int, param2:Boolean) : void
        {
            if (param1 < 0 || param1 >= selectArr.length)
            {
                return;
            }
            var _loc_3:* = selectArr[param1] as ISelect;
            _loc_3.enable = param2;
            return;
        }// end function

        public function addSelectButton(param1:ISelect, param2:Number = 0, param3:Number = 0, param4:String = null) : void
        {
            var _loc_5:* = param1.getSkin();
            param1.getSkin().x = param2;
            _loc_5.y = param3;
            addChild(_loc_5);
            _loc_5.addEventListener(SelectEvent.CLICK, buttonClickHlr);
            buttonArr.push(_loc_5);
            selectArr.push(param1);
            if (param4)
            {
                keyArr.push(param4);
            }
            else
            {
                keyArr.push(_loc_5.name);
            }
            return;
        }// end function

        private function buttonClickHlr(event:SelectEvent) : void
        {
            var _loc_2:* = buttonArr.indexOf(event.currentTarget);
            if (_loc_2 == index)
            {
                return;
            }
            dispatchEvent(new RadioEvent(RadioEvent.CLICK, false, false, _loc_2, keyArr[_loc_2]));
            return;
        }// end function

        public function set activeIndex(param1:int) : void
        {
            var _loc_2:ISelect = null;
            var _loc_3:int = 0;
            while (_loc_3 < selectArr.length)
            {
                
                _loc_2 = selectArr[_loc_3] as ISelect;
                _loc_2.selected = false;
                _loc_3++;
            }
            if (param1 >= 0 && param1 < selectArr.length)
            {
                index = param1;
                _loc_2 = selectArr[param1] as ISelect;
                _loc_2.selected = true;
            }
            else
            {
                index = -1;
            }
            var _loc_4:* = index >= 0;
            this.buttonMode = index >= 0;
            this.useHandCursor = _loc_4;
            return;
        }// end function

        public function get activeIndex() : int
        {
            return index;
        }// end function

        public function setBackground(param1:DisplayObject, param2:Number = 0, param3:Number = 0) : void
        {
            param1.x = param2;
            param1.y = param3;
            addChildAt(param1, 0);
            return;
        }// end function

        public function set activeKey(param1:String) : void
        {
            var _loc_2:* = keyArr.indexOf(param1);
            activeIndex = _loc_2;
            return;
        }// end function

        public function get buttonNum() : uint
        {
            return buttonArr.length;
        }// end function

    }
}
